package com.yl.chainStore.entity.pay

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler
import com.yl.chainStore.common.Constants
import com.yl.chainStore.common.enums.Status
import com.yl.common.annotation.NoArg
import org.apache.ibatis.type.JdbcType
import java.math.BigDecimal
import java.math.RoundingMode
import java.util.*

/**
 * <p>
 *
 * </p>
 *
 * @author cxw
 * @since 2021-07-10
 */
@NoArg
@TableName(value = "pay_customer_order_detail",autoResultMap = true)
data class PayCustomerOrderDetail(

	/**
	 * id
	 */
	@TableId(value = "id", type = IdType.AUTO)
	var id: Long = 0,


	/**
	 * 订单id
	 */
	@TableField("order_id")
	var orderId: Long? = 0,

	/**
	 * 服务id
	 */
	@TableField("item_id")
	var itemId: Long,

	/**
	 * typeId
	 */
	@TableField(exist = false)
	var typeId: Long ? = null,

	@TableField(exist = false)
	var itemName: String? = null,
	/**
	 * 规格
	 */
	@TableField(exist = false)
	var specification: String? = null,

	/**
	 * 单位
	 */
	@TableField(exist = false)
	var unit: String? = null,

	/**
	 * 品牌
	 */
	@TableField(exist = false)
	var brand: String? = null,

	/**
	 * 数量
	 */
	@TableField("number")
	var number: Int,

	/**
	 * 状态备注 NEW_ADD 新增
	 *         END 结束
	 */
	@TableField("status")
	var status: Status = Status.NEW_ADD,

	/**
	 * 备注
	 */
	@TableField("remark")
	var remark: String? = null,

	/**
	 * 技加工物品是否到货，1为否，0为是
	 */
	@TableField("goods_arrive")
	var goodsArrive: Int? = null,

	/**
	 * 单价(原价)
	 */
	@TableField("price")
	var price: Long,

	/**
	 * 医生
	 */
	@TableField("doctor_id")
	var doctorId: Long ?= null,

	/**
	 * 医生
	 */
	@TableField(exist = false)
	var doctorName: String ?= null,

	/**
	 * 护士
	 */
	@TableField("nurse_id")
	var nurseId: Long? = null,

	/**
	 * 护士
	 */
	@TableField(exist = false)
	var nurseName: String ?= null,

	/**
	 * 咨询师
	 */
	@TableField("consultant_id")
	var consultantId:Long ?= null,

	/**
	 * 咨询师
	 */
	@TableField(exist = false)
	var consultantName:String ?= null,

	/**
	 * 网电咨询师
	 */
	@TableField("net_consultant_id")
	var netConsultantId:Long ?= null,

	/**
	 * 网店咨询师名称
	 */
	@TableField(exist = false)
	var netConsultantName:String ?= null,

	/**
	 * 牙位
	 */
	@TableField(value = "tooth_bit",jdbcType = JdbcType.OTHER,typeHandler = FastjsonTypeHandler::class)
	var toothBit: Any? = null,

	/**
	 * 是否为赠品
	 */
	@TableField("gift")
	var gift: Int = 0,

	/**
	 * 实际（折后）价格，单价，（下单后会被修改）
	 */
	@TableField("real_price")
	var realPrice: Long = price,

	/**
	 * 下单后单价(不变的)
	 */
	@TableField("item_price")
	var itemPrice:Long = realPrice,

	/**
	 * 下单后总价(不变的)
	 */
	@TableField("item_sum_money")
	var itemSumMoney:Long = itemPrice.times(number),

	/**
	 * 实际（折后）总价 （下单后会被修改）
	 */
	@TableField("real_money")
	var realMoney: Long = realPrice.times(number),

	/**
	 * 开始使用时间
	 */
	@TableField("use_start_time")
	var useStartTime:Date ?= null,


	/**
	 * 已经被退款的数量
	 */
	@TableField(exist = false)
	var refundCount :Int ?= null,

	/**
	 * 已经被退款的金额
	 */
	@TableField(exist = false)
	var detailRefundSumMoney:Long ?= null

) {
	/**
	 * 单价显示
	 */
	@TableField(exist = false)
	var priceShow: BigDecimal? = null
		get() {

			if (field == null) {
				return BigDecimal(price.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(2, RoundingMode.HALF_UP)
			}
			return field
		}
		set(value) {
			if (value != null) {
				price = (value.multiply(BigDecimal(Constants.OtherConfig.MONEY_TO_DB_DOUBLE))).toLong()
				field = value
			}
		}

	/**
	 * 总价显示
	 */
	@TableField(exist = false)
	var moneyShow: BigDecimal? = null
		get() {
			if (field == null) {
				return BigDecimal(price.times(number).div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(
					2,
					RoundingMode.HALF_UP
				)
			}
			return field
		}

	/**
	 * 折后单价显示
	 */
	@TableField(exist = false)
	var realPriceShow: BigDecimal? = null
		get() {


				return BigDecimal(realPrice.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(
					2,
					RoundingMode.HALF_UP
				)


		}

	/**
	 * 折后总价显示
	 */
	@TableField(exist = false)
	var realMoneyShow: BigDecimal? = null
		get() {
			if (field == null) {
				return BigDecimal(realMoney.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(
					2,
					RoundingMode.HALF_UP
				)
			}
			return field
		}

	@TableField(exist = false)
	var detailRefundSumMoneyShow : BigDecimal? = null
		get() {
			if (detailRefundSumMoney != null) {
				return BigDecimal(detailRefundSumMoney!!.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(
					2,
					RoundingMode.HALF_UP
				)
			}
			return null
		}






}
